import { defineConfig } from 'vite';
// import AutoImport from 'unplugin-auto-import/vite';
// import Components from 'unplugin-vue-components/vite';
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import resolveExternalsPlugin from 'vite-plugin-resolve-externals';
import vue from '@vitejs/plugin-vue';
import path from 'path'; //关键
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

// const tenantId = '200158';
export default defineConfig(({ mode }) => {
	return {
		base: mode === 'production' ? '/graphics-engine' : './',
		//关键
		resolve: {
			alias: {
				'@': path.resolve('./src'), // 相对路径别名配置，使用 @ 代替 src
				'@CIF': path.resolve('./src/views/CIF'),
				'@packages': path.resolve('./packages'),
				'@utils': path.resolve('./src/utils')
			}
		},
		plugins: [
			vue(),
			resolveExternalsPlugin({
				echarts: 'echarts',
				turf: '@turf',
				lodash: '_',
				Color: 'Color' // 这个名字可以直接打印window，看window上挂的是什么名字，就写什么名字
			}),
			createSvgIconsPlugin({
				iconDirs: [path.resolve(process.cwd(), 'packages/assets/svg')], // SVG 存放路径
				symbolId: 'icon-[name]'
			})
			// AutoImport({
			// 	resolvers: [ElementPlusResolver()]
			// }),
			// Components({
			// 	resolvers: [ElementPlusResolver()]
			// })
		],
		rollupOptions: {
			// external: ['vue'],
			output: {
				// // 在 MD 构建模式下为这些外部化的依赖提供一个全局变量
				globals: {
					// vue: 'Vue'
				}
			}
		},
		server: {
			port: 8001,
			proxy: {
				'/bimserver': {
					target: 'http://39.174.170.163:8082', // 设计态
					changeOrigin: true
					// rewrite: (path) => path.replace(/^\/api/, '')
				},
				'/fusion-cdn/': {
					target: 'http://119.3.217.12:8002',
					changeOrigin: true
				},
				// '/graphics-engine/api': {
				// 	// target: 'http://localhost:8080', // 本地启动主项目
				// 	// target: 'http://192.168.10.95:8080', // 黄
				// 	// target: 'http://119.3.217.12:88', // 线上
				// 	// target: 'http://119.3.237.66:88', // 设计态-正式
				// 	target: 'http://120.46.39.25:10010' // 设计态-测试
				// },
				'/api': {
					// 	// target: 'http://localhost:8080', // 本地启动主项目
					// 	// target: 'http://192.168.10.95:8080', // 黄
					// 	// target: 'http://119.3.217.12:88', // 线上
					// 	// target: 'http://119.3.237.66:88', // 设计态
					target: 'http://test.fusionpaas.com:10010', // 测试环境
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/api/, '')
				},
				'/graphics-engine/fusion-cdn/': {
					target: 'http://119.3.217.12:8002',
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/graphics-engine\/fusion-cdn/, '/fusion-cdn')
				},
				'/graphics-engine/bimserver': {
					target: 'http://39.174.170.163:8082',
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/graphics-engine/, '')
				}
				// '/cif_assets': {
				// 	target: 'http://119.3.237.66:9000',
				// 	changeOrigin: true,
				// 	rewrite: (path) => path.replace(/^\/cif_assets/, `/uuu/${tenantId}/cif_assets`)
				// }
			}
		}
	};
});
